source("../../lib/som-utils.R")
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
source("../../lib/maps-utils.R")
Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
mpr.set_base_path_analysis()
model <- mpr.load_model("som-145.rds.xz")
summary(model)
SOM of size 5x5 with a hexagonal topology and a bubble neighbourhood function.
The number of data layers is 1.
Distance measure(s) used: sumofsquares.
Training data included: 156652 objects.
Mean distance to the closest unit in the map: 0.874.
plot(model, type="changes")
df <- mpr.load_data("datos_semana_2k.csv.xz")
df
summary(df)
id_estacion fecha fecha_cnt tmax
Length:156652 Length:156652 Min. : 1.00 Min. :-109.0
Class :character Class :character 1st Qu.:13.00 1st Qu.: 147.0
Mode :character Mode :character Median :27.00 Median : 201.0
Mean :26.53 Mean : 202.1
3rd Qu.:40.00 3rd Qu.: 262.0
Max. :53.00 Max. : 442.0
tmin precip nevada prof_nieve
Min. :-189.00 Min. : 0.00 Min. :0 Min. : 0.000
1st Qu.: 48.00 1st Qu.: 0.00 1st Qu.:0 1st Qu.: 0.000
Median : 98.00 Median : 3.00 Median :0 Median : 0.000
Mean : 98.13 Mean : 16.92 Mean :0 Mean : 0.604
3rd Qu.: 152.00 3rd Qu.: 20.00 3rd Qu.:0 3rd Qu.: 0.000
Max. : 272.00 Max. :690.00 Max. :0 Max. :1073.000
longitud latitud altitud
Min. :27.82 Min. :-17.889 Min. : 1.0
1st Qu.:39.01 1st Qu.: -4.850 1st Qu.: 44.0
Median :41.22 Median : -1.411 Median : 263.0
Mean :40.05 Mean : -2.426 Mean : 478.5
3rd Qu.:42.19 3rd Qu.: 1.272 3rd Qu.: 687.0
Max. :43.57 Max. : 4.216 Max. :2535.0
world <- ne_countries(scale = "medium", returnclass = "sf")
spain <- subset(world, admin == "Spain")
plot(model, type="count", shape = "straight", palette.name = mpr.degrade.bleu)
NĂºmero de elementos en cada celda:
nb <- table(model$unit.classif)
print(nb)
1 2 3 4 5 6 7 8 9 10 11 12 13
4443 11003 4807 3907 9789 7109 8121 8370 3561 3891 6694 7120 3846
14 15 16 17 18 19 20 21 22 23 24 25
5155 6460 3593 2318 5366 5832 5614 7946 3693 7323 7109 13582
ComprobaciĂ³n de nodos vacĂos:
dim_model <- 5*5;
len_nb = length(nb);
empty_nodes <- dim_model != len_nb;
if (empty_nodes) {
print(paste("[Warning] Existen nodos vacĂos: ", len_nb, "/", dim_model))
}
plot(model, type="dist.neighbours", shape = "straight")
model_colnames = c("fecha_cnt", "tmax", "tmin", "longitud", "latitud", "altitud")
model_ncol = length(model_colnames)
plot(model, shape = "straight")
par(mfrow=c(3,4))
for (j in 1:model_ncol) {
plot(model, type="property", property=getCodes(model,1)[,j],
palette.name=mpr.coolBlueHotRed,
main=model_colnames[j],
cex=0.5, shape = "straight")
}
if (!empty_nodes) {
cor <- apply(getCodes(model,1), 2, mpr.weighted.correlation, w=nb, som=model)
print(cor)
}
fecha_cnt tmax tmin longitud latitud altitud
[1,] 0.3514805 0.7931994 0.90137087 -0.5066463 -0.2597551 -0.4093813
[2,] 0.7120974 0.1095887 0.09326044 0.4392518 0.4500446 0.1089092
RepresentaciĂ³n de cada variable en un mapa de factores:
if (!empty_nodes) {
par(mfrow=c(1,1))
plot(cor[1,], cor[2,], xlim=c(-1,1), ylim=c(-1,1), type="n")
lines(c(-1,1),c(0,0))
lines(c(0,0),c(-1,1))
text(cor[1,], cor[2,], labels=model_colnames, cex=0.75)
symbols(0,0,circles=1,inches=F,add=T)
}
Importancia de cada variable - varianza ponderada por el tamaño de la celda:
if (!empty_nodes) {
sigma2 <- sqrt(apply(getCodes(model,1),2,function(x,effectif)
{m<-sum(effectif*(x-weighted.mean(x,effectif))^2)/(sum(effectif)-1)},
effectif=nb))
print(sort(sigma2,decreasing=T))
}
longitud latitud fecha_cnt tmax tmin altitud
0.9601979 0.9279965 0.9259201 0.9178520 0.9037189 0.8873639
if (!empty_nodes) {
hac <- mpr.hac(model, nb)
}
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=3)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=3)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-31.0 Min. :-161.00 Min. : 0.00 Min. :0
1st Qu.:13.00 1st Qu.:152.0 1st Qu.: 52.00 1st Qu.: 0.00 1st Qu.:0
Median :26.00 Median :203.0 Median : 99.00 Median : 3.00 Median :0
Mean :26.52 Mean :208.6 Mean : 99.42 Mean : 16.49 Mean :0
3rd Qu.:40.00 3rd Qu.:267.0 3rd Qu.: 149.00 3rd Qu.: 20.00 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.00 Max. :690.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.56 1st Qu.:-4.488 1st Qu.: 52.0
Median : 0.00000 Median :41.29 Median :-1.293 Median : 258.0
Mean : 0.06502 Mean :40.73 Mean :-1.680 Mean : 367.1
3rd Qu.: 0.00000 3rd Qu.:42.12 3rd Qu.: 1.296 3rd Qu.: 628.0
Max. :299.00000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 14.0 Min. :-34.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:148.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.31 Mean :229.6 Mean :165.2 Mean : 6.232 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :490.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.04 Mean : 369.8
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 3.00
Median :27.00 Median : 77.00 Median : 10.00 Median : 19.00
Mean :26.83 Mean : 82.58 Mean : 12.64 Mean : 33.69
3rd Qu.:40.00 3rd Qu.: 137.00 3rd Qu.: 61.00 3rd Qu.: 48.00
Max. :53.00 Max. : 263.00 Max. : 154.00 Max. :615.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.784 Mean :42.23 Mean : 0.7367
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1002
1st Qu.:1894
Median :2230
Mean :2152
3rd Qu.:2400
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=4)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=4)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-22.0 Min. :-161.00 Min. : 0.00 Min. :0
1st Qu.: 6.0 1st Qu.:135.0 1st Qu.: 32.00 1st Qu.: 0.00 1st Qu.:0
Median :11.0 Median :170.0 Median : 66.00 Median : 6.00 Median :0
Mean :11.6 Mean :169.4 Mean : 64.98 Mean : 18.59 Mean :0
3rd Qu.:17.0 3rd Qu.:205.0 3rd Qu.: 99.00 3rd Qu.: 25.00 3rd Qu.:0
Max. :31.0 Max. :323.0 Max. : 202.00 Max. :608.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1
1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.:-4.680 1st Qu.: 47
Median : 0.0000 Median :41.32 Median :-1.293 Median : 251
Mean : 0.1037 Mean :40.76 Mean :-1.686 Mean : 356
3rd Qu.: 0.0000 3rd Qu.:42.18 3rd Qu.: 1.331 3rd Qu.: 617
Max. :299.0000 Max. :43.57 Max. : 4.216 Max. :1572
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 14.0 Min. :-34.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:148.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.31 Mean :229.6 Mean :165.2 Mean : 6.232 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :490.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.04 Mean : 369.8
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :14.00 Min. :-31.0 Min. :-155.0 Min. : 0.00 Min. :0
1st Qu.:30.00 1st Qu.:180.0 1st Qu.: 82.0 1st Qu.: 0.00 1st Qu.:0
Median :38.00 Median :250.0 Median : 133.0 Median : 2.00 Median :0
Mean :37.46 Mean :237.4 Mean : 124.7 Mean : 14.96 Mean :0
3rd Qu.:45.00 3rd Qu.:296.0 3rd Qu.: 173.0 3rd Qu.: 16.00 3rd Qu.:0
Max. :53.00 Max. :442.0 Max. : 272.0 Max. :690.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:39.56 1st Qu.:-4.127 1st Qu.: 52.0
Median : 0.00000 Median :41.22 Median :-1.293 Median : 261.0
Mean : 0.03667 Mean :40.72 Mean :-1.675 Mean : 375.3
3rd Qu.: 0.00000 3rd Qu.:42.08 3rd Qu.: 1.201 3rd Qu.: 656.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 3.00
Median :27.00 Median : 77.00 Median : 10.00 Median : 19.00
Mean :26.83 Mean : 82.58 Mean : 12.64 Mean : 33.69
3rd Qu.:40.00 3rd Qu.: 137.00 3rd Qu.: 61.00 3rd Qu.: 48.00
Max. :53.00 Max. : 263.00 Max. : 154.00 Max. :615.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.784 Mean :42.23 Mean : 0.7367
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1002
1st Qu.:1894
Median :2230
Mean :2152
3rd Qu.:2400
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=5)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=5)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. :-22.0 Min. :-161.00 Min. : 0.00 Min. :0
1st Qu.: 6.0 1st Qu.:135.0 1st Qu.: 32.00 1st Qu.: 0.00 1st Qu.:0
Median :11.0 Median :170.0 Median : 66.00 Median : 6.00 Median :0
Mean :11.6 Mean :169.4 Mean : 64.98 Mean : 18.59 Mean :0
3rd Qu.:17.0 3rd Qu.:205.0 3rd Qu.: 99.00 3rd Qu.: 25.00 3rd Qu.:0
Max. :31.0 Max. :323.0 Max. : 202.00 Max. :608.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :35.28 Min. :-8.624 Min. : 1
1st Qu.: 0.0000 1st Qu.:39.56 1st Qu.:-4.680 1st Qu.: 47
Median : 0.0000 Median :41.32 Median :-1.293 Median : 251
Mean : 0.1037 Mean :40.76 Mean :-1.686 Mean : 356
3rd Qu.: 0.0000 3rd Qu.:42.18 3rd Qu.: 1.331 3rd Qu.: 617
Max. :299.0000 Max. :43.57 Max. : 4.216 Max. :1572
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 14.0 Min. :-34.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:148.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.31 Mean :229.6 Mean :165.2 Mean : 6.232 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :490.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.04 Mean : 369.8
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. :29.00 Min. :-31.0 Min. :-155.0 Min. : 0.00 Min. :0
1st Qu.:44.00 1st Qu.:123.0 1st Qu.: 29.0 1st Qu.: 0.00 1st Qu.:0
Median :47.00 Median :157.0 Median : 62.0 Median : 6.00 Median :0
Mean :46.87 Mean :154.9 Mean : 58.3 Mean : 22.19 Mean :0
3rd Qu.:50.00 3rd Qu.:186.0 3rd Qu.: 89.0 3rd Qu.: 28.00 3rd Qu.:0
Max. :53.00 Max. :297.0 Max. : 187.0 Max. :690.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.:-4.680 1st Qu.: 81.0
Median : 0.00000 Median :41.39 Median :-1.863 Median : 412.0
Mean : 0.09416 Mean :40.84 Mean :-1.924 Mean : 438.2
3rd Qu.: 0.00000 3rd Qu.:42.23 3rd Qu.: 1.165 3rd Qu.: 735.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. :14.00 Min. :164.0 Min. : 46.0 Min. : 0.00 Min. :0
1st Qu.:27.00 1st Qu.:253.0 1st Qu.:134.0 1st Qu.: 0.00 1st Qu.:0
Median :32.00 Median :284.0 Median :161.0 Median : 1.00 Median :0
Mean :32.25 Mean :283.1 Mean :161.5 Mean : 10.95 Mean :0
3rd Qu.:37.00 3rd Qu.:312.0 3rd Qu.:188.0 3rd Qu.: 11.00 3rd Qu.:0
Max. :52.00 Max. :442.0 Max. :272.0 Max. :610.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:39.49 1st Qu.:-4.049 1st Qu.: 43.3
Median :0.00e+00 Median :41.17 Median :-1.117 Median : 192.0
Mean :4.78e-03 Mean :40.65 Mean :-1.538 Mean : 340.4
3rd Qu.:0.00e+00 3rd Qu.:42.00 3rd Qu.: 1.331 3rd Qu.: 611.0
Max. :1.73e+02 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 3.00
Median :27.00 Median : 77.00 Median : 10.00 Median : 19.00
Mean :26.83 Mean : 82.58 Mean : 12.64 Mean : 33.69
3rd Qu.:40.00 3rd Qu.: 137.00 3rd Qu.: 61.00 3rd Qu.: 48.00
Max. :53.00 Max. : 263.00 Max. : 154.00 Max. :615.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.784 Mean :42.23 Mean : 0.7367
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1002
1st Qu.:1894
Median :2230
Mean :2152
3rd Qu.:2400
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=6)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=6)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 54.0 Min. :-33.00 Min. : 0.0 Min. :0
1st Qu.: 8.0 1st Qu.:159.0 1st Qu.: 57.00 1st Qu.: 0.0 1st Qu.:0
Median :14.0 Median :185.0 Median : 81.00 Median : 6.0 Median :0
Mean :13.2 Mean :187.9 Mean : 83.32 Mean : 19.3 Mean :0
3rd Qu.:18.0 3rd Qu.:216.0 3rd Qu.:109.00 3rd Qu.: 26.0 3rd Qu.:0
Max. :31.0 Max. :323.0 Max. :202.00 Max. :523.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:38.88 1st Qu.:-5.346 1st Qu.: 32.0
Median : 0.00000 Median :41.20 Median :-1.169 Median : 98.0
Mean : 0.03746 Mean :40.57 Mean :-1.784 Mean : 250.4
3rd Qu.: 0.00000 3rd Qu.:42.18 3rd Qu.: 1.296 3rd Qu.: 412.0
Max. :164.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 14.0 Min. :-34.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:148.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.31 Mean :229.6 Mean :165.2 Mean : 6.232 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :490.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.04 Mean : 369.8
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-22 Min. :-161.00 Min. : 0.0 Min. :0
1st Qu.: 3.000 1st Qu.: 90 1st Qu.: -11.00 1st Qu.: 0.0 1st Qu.:0
Median : 6.000 Median :112 Median : 9.00 Median : 6.0 Median :0
Mean : 6.479 Mean :110 Mean : 6.22 Mean : 16.3 Mean :0
3rd Qu.: 9.000 3rd Qu.:132 3rd Qu.: 26.00 3rd Qu.: 21.0 3rd Qu.:0
Max. :28.000 Max. :209 Max. : 82.00 Max. :608.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :37.16 Min. :-8.411 Min. : 2
1st Qu.: 0.0000 1st Qu.:40.76 1st Qu.:-3.764 1st Qu.: 513
Median : 0.0000 Median :41.63 Median :-1.636 Median : 690
Mean : 0.3157 Mean :41.37 Mean :-1.370 Mean : 694
3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 1.331 3rd Qu.: 900
Max. :299.0000 Max. :43.36 Max. : 4.216 Max. :1572
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. :29.00 Min. :-31.0 Min. :-155.0 Min. : 0.00 Min. :0
1st Qu.:44.00 1st Qu.:123.0 1st Qu.: 29.0 1st Qu.: 0.00 1st Qu.:0
Median :47.00 Median :157.0 Median : 62.0 Median : 6.00 Median :0
Mean :46.87 Mean :154.9 Mean : 58.3 Mean : 22.19 Mean :0
3rd Qu.:50.00 3rd Qu.:186.0 3rd Qu.: 89.0 3rd Qu.: 28.00 3rd Qu.:0
Max. :53.00 Max. :297.0 Max. : 187.0 Max. :690.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.:-4.680 1st Qu.: 81.0
Median : 0.00000 Median :41.39 Median :-1.863 Median : 412.0
Mean : 0.09416 Mean :40.84 Mean :-1.924 Mean : 438.2
3rd Qu.: 0.00000 3rd Qu.:42.23 3rd Qu.: 1.165 3rd Qu.: 735.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :14.00 Min. :164.0 Min. : 46.0 Min. : 0.00 Min. :0
1st Qu.:27.00 1st Qu.:253.0 1st Qu.:134.0 1st Qu.: 0.00 1st Qu.:0
Median :32.00 Median :284.0 Median :161.0 Median : 1.00 Median :0
Mean :32.25 Mean :283.1 Mean :161.5 Mean : 10.95 Mean :0
3rd Qu.:37.00 3rd Qu.:312.0 3rd Qu.:188.0 3rd Qu.: 11.00 3rd Qu.:0
Max. :52.00 Max. :442.0 Max. :272.0 Max. :610.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:39.49 1st Qu.:-4.049 1st Qu.: 43.3
Median :0.00e+00 Median :41.17 Median :-1.117 Median : 192.0
Mean :4.78e-03 Mean :40.65 Mean :-1.538 Mean : 340.4
3rd Qu.:0.00e+00 3rd Qu.:42.00 3rd Qu.: 1.331 3rd Qu.: 611.0
Max. :1.73e+02 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.00 Min. : 0.00
1st Qu.:14.00 1st Qu.: 29.00 1st Qu.: -33.00 1st Qu.: 3.00
Median :27.00 Median : 77.00 Median : 10.00 Median : 19.00
Mean :26.83 Mean : 82.58 Mean : 12.64 Mean : 33.69
3rd Qu.:40.00 3rd Qu.: 137.00 3rd Qu.: 61.00 3rd Qu.: 48.00
Max. :53.00 Max. : 263.00 Max. : 154.00 Max. :615.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.000 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.000 Median :42.47 Median : 1.0544
Mean :0 Mean : 8.784 Mean :42.23 Mean : 0.7367
3rd Qu.:0 3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.000 Max. :42.77 Max. : 2.4378
altitud
Min. :1002
1st Qu.:1894
Median :2230
Mean :2152
3rd Qu.:2400
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=8)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=8)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 54.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 9.00 1st Qu.:156.0 1st Qu.: 54.00 1st Qu.: 0.00 1st Qu.:0
Median :14.00 Median :182.0 Median : 77.00 Median : 7.00 Median :0
Mean :13.57 Mean :184.9 Mean : 79.51 Mean : 20.33 Mean :0
3rd Qu.:19.00 3rd Qu.:213.0 3rd Qu.:103.00 3rd Qu.: 27.00 3rd Qu.:0
Max. :31.00 Max. :322.0 Max. :187.00 Max. :523.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :37.79 Min. :-8.6239 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.72 1st Qu.:-3.6781 1st Qu.: 43.0
Median : 0.00000 Median :41.57 Median : 0.4914 Median : 147.0
Mean : 0.04412 Mean :41.41 Mean :-1.0361 Mean : 284.8
3rd Qu.: 0.00000 3rd Qu.:42.37 3rd Qu.: 1.6331 3rd Qu.: 445.0
Max. :164.00000 Max. :43.57 Max. : 4.2156 Max. :1572.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 86.0 Min. :-29.00 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:170.0 1st Qu.: 71.00 1st Qu.: 0.00 1st Qu.:0
Median :12.00 Median :195.0 Median :101.00 Median : 2.00 Median :0
Mean :11.68 Mean :200.2 Mean : 98.84 Mean : 15.12 Mean :0
3rd Qu.:17.00 3rd Qu.:228.0 3rd Qu.:127.00 3rd Qu.: 19.00 3rd Qu.:0
Max. :28.00 Max. :323.0 Max. :202.00 Max. :354.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.949 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:36.64 1st Qu.:-6.257 1st Qu.: 21.0
Median : 0.00000 Median :37.16 Median :-5.598 Median : 47.0
Mean : 0.01033 Mean :37.12 Mean :-4.833 Mean :110.6
3rd Qu.: 0.00000 3rd Qu.:37.78 3rd Qu.:-3.789 3rd Qu.: 90.0
Max. :10.00000 Max. :39.88 Max. :-0.500 Max. :717.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 14.0 Min. :-34.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:148.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.31 Mean :229.6 Mean :165.2 Mean : 6.232 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :490.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.04 Mean : 369.8
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-22 Min. :-161.00 Min. : 0.0 Min. :0
1st Qu.: 3.000 1st Qu.: 90 1st Qu.: -11.00 1st Qu.: 0.0 1st Qu.:0
Median : 6.000 Median :112 Median : 9.00 Median : 6.0 Median :0
Mean : 6.479 Mean :110 Mean : 6.22 Mean : 16.3 Mean :0
3rd Qu.: 9.000 3rd Qu.:132 3rd Qu.: 26.00 3rd Qu.: 21.0 3rd Qu.:0
Max. :28.000 Max. :209 Max. : 82.00 Max. :608.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :37.16 Min. :-8.411 Min. : 2
1st Qu.: 0.0000 1st Qu.:40.76 1st Qu.:-3.764 1st Qu.: 513
Median : 0.0000 Median :41.63 Median :-1.636 Median : 690
Mean : 0.3157 Mean :41.37 Mean :-1.370 Mean : 694
3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 1.331 3rd Qu.: 900
Max. :299.0000 Max. :43.36 Max. : 4.216 Max. :1572
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. :29.00 Min. :-31.0 Min. :-155.0 Min. : 0.00 Min. :0
1st Qu.:44.00 1st Qu.:123.0 1st Qu.: 29.0 1st Qu.: 0.00 1st Qu.:0
Median :47.00 Median :157.0 Median : 62.0 Median : 6.00 Median :0
Mean :46.87 Mean :154.9 Mean : 58.3 Mean : 22.19 Mean :0
3rd Qu.:50.00 3rd Qu.:186.0 3rd Qu.: 89.0 3rd Qu.: 28.00 3rd Qu.:0
Max. :53.00 Max. :297.0 Max. : 187.0 Max. :690.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.:-4.680 1st Qu.: 81.0
Median : 0.00000 Median :41.39 Median :-1.863 Median : 412.0
Mean : 0.09416 Mean :40.84 Mean :-1.924 Mean : 438.2
3rd Qu.: 0.00000 3rd Qu.:42.23 3rd Qu.: 1.165 3rd Qu.: 735.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :14.00 Min. :164.0 Min. : 46.0 Min. : 0.00 Min. :0
1st Qu.:27.00 1st Qu.:253.0 1st Qu.:134.0 1st Qu.: 0.00 1st Qu.:0
Median :32.00 Median :284.0 Median :161.0 Median : 1.00 Median :0
Mean :32.25 Mean :283.1 Mean :161.5 Mean : 10.95 Mean :0
3rd Qu.:37.00 3rd Qu.:312.0 3rd Qu.:188.0 3rd Qu.: 11.00 3rd Qu.:0
Max. :52.00 Max. :442.0 Max. :272.0 Max. :610.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.:0.00e+00 1st Qu.:39.49 1st Qu.:-4.049 1st Qu.: 43.3
Median :0.00e+00 Median :41.17 Median :-1.117 Median : 192.0
Mean :4.78e-03 Mean :40.65 Mean :-1.538 Mean : 340.4
3rd Qu.:0.00e+00 3rd Qu.:42.00 3rd Qu.: 1.331 3rd Qu.: 611.0
Max. :1.73e+02 Max. :43.57 Max. : 4.216 Max. :1894.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-79.0 Min. :-146.00 Min. : 0.00 Min. :0
1st Qu.:28.00 1st Qu.: 66.0 1st Qu.: 6.00 1st Qu.: 2.00 1st Qu.:0
Median :37.00 Median :120.0 Median : 48.00 Median : 16.00 Median :0
Mean :36.31 Mean :112.7 Mean : 40.82 Mean : 30.67 Mean :0
3rd Qu.:45.00 3rd Qu.:160.2 3rd Qu.: 81.00 3rd Qu.: 42.00 3rd Qu.:0
Max. :53.00 Max. :263.0 Max. : 154.00 Max. :459.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7317 1st Qu.:1894
Median : 0.000 Median :42.47 Median : 1.0544 Median :2230
Mean : 2.256 Mean :42.22 Mean : 0.7342 Mean :2133
3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150 3rd Qu.:2400
Max. :805.000 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.00 Min. : 0.00
1st Qu.: 5.00 1st Qu.: 4.00 1st Qu.: -60.00 1st Qu.: 6.00
Median :10.00 Median : 34.00 Median : -31.00 Median : 25.00
Mean :10.56 Mean : 30.98 Mean : -35.71 Mean : 38.85
3rd Qu.:15.00 3rd Qu.: 62.00 3rd Qu.: -7.00 3rd Qu.: 55.00
Max. :25.00 Max. : 132.00 Max. : 56.00 Max. :615.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.00 Median :42.47 Median : 1.0544
Mean :0 Mean : 19.98 Mean :42.25 Mean : 0.7410
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1002
1st Qu.:1971
Median :2247
Mean :2186
3rd Qu.:2400
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) {
plot(hac, hang=-1, labels=F)
rect.hclust(hac, k=10)
}
A quĂ© clĂºster pertenece cada nodo del mapa de kohonen:
if (!empty_nodes) {
groups <- cutree(hac, k=10)
plot(model, type="mapping",
bgcol=c("steelblue1","sienna1","yellowgreen","red","blue","yellow","purple","green","white","#1f77b4", '#ff7f0e', '#2ca02c', '#d62728', '#9467bd', '#8c564b', '#e377c2')[groups],
shape = "straight", labels = "")
add.cluster.boundaries(model, clustering=groups)
}
if (!empty_nodes) {
# Asignamos a cada registro su clĂºster
df$cluster <- groups[model$unit.classif]
}
Nuevos dataframes por cluster
if (!empty_nodes) {
# Creo nuevos dataframes, uno por cada clĂºster.
df.cluster01 <- subset(df, cluster==1)
df.cluster02 <- subset(df, cluster==2)
df.cluster03 <- subset(df, cluster==3)
df.cluster04 <- subset(df, cluster==4)
df.cluster05 <- subset(df, cluster==5)
df.cluster06 <- subset(df, cluster==6)
df.cluster07 <- subset(df, cluster==7)
df.cluster08 <- subset(df, cluster==8)
df.cluster09 <- subset(df, cluster==9)
df.cluster10 <- subset(df, cluster==10)
# Extraigo del dataframe las features.
df.cluster01 <- select(df.cluster01, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster02 <- select(df.cluster02, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster03 <- select(df.cluster03, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster04 <- select(df.cluster04, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster05 <- select(df.cluster05, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster06 <- select(df.cluster06, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster07 <- select(df.cluster07, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster08 <- select(df.cluster08, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster09 <- select(df.cluster09, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
df.cluster10 <- select(df.cluster10, fecha_cnt, tmax, tmin, precip, nevada, prof_nieve, longitud, latitud, altitud)
}
if (!empty_nodes) summary(df.cluster01)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 54.0 Min. :-33.00 Min. : 0.00 Min. :0
1st Qu.: 7.00 1st Qu.:134.0 1st Qu.: 56.00 1st Qu.: 5.00 1st Qu.:0
Median :12.00 Median :159.0 Median : 80.00 Median : 21.00 Median :0
Mean :12.45 Mean :161.8 Mean : 78.26 Mean : 34.75 Mean :0
3rd Qu.:18.00 3rd Qu.:189.0 3rd Qu.:102.00 3rd Qu.: 48.00 3rd Qu.:0
Max. :29.00 Max. :289.0 Max. :160.00 Max. :496.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :39.47 Min. :-8.624 Min. : 4.0
1st Qu.: 0.0000 1st Qu.:42.56 1st Qu.:-8.411 1st Qu.: 52.0
Median : 0.0000 Median :43.31 Median :-6.044 Median :127.0
Mean : 0.1253 Mean :43.06 Mean :-6.062 Mean :187.3
3rd Qu.: 0.0000 3rd Qu.:43.43 3rd Qu.:-3.831 3rd Qu.:336.0
Max. :154.0000 Max. :43.57 Max. :-1.636 Max. :775.0
if (!empty_nodes) summary(df.cluster02)
fecha_cnt tmax tmin precip nevada
Min. : 1.0 Min. : 90.0 Min. :-29.00 Min. : 0.00 Min. :0
1st Qu.:10.0 1st Qu.:164.0 1st Qu.: 54.00 1st Qu.: 0.00 1st Qu.:0
Median :15.0 Median :188.0 Median : 76.00 Median : 5.00 Median :0
Mean :13.9 Mean :191.7 Mean : 79.87 Mean : 16.14 Mean :0
3rd Qu.:19.0 3rd Qu.:219.0 3rd Qu.:103.00 3rd Qu.: 21.00 3rd Qu.:0
Max. :31.0 Max. :322.0 Max. :187.00 Max. :523.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :37.79 Min. :-5.7333 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.35 1st Qu.:-0.5000 1st Qu.: 35.0
Median : 0.00000 Median :41.22 Median : 0.8031 Median : 176.0
Mean : 0.02048 Mean :40.93 Mean : 0.4271 Mean : 313.1
3rd Qu.: 0.00000 3rd Qu.:41.68 3rd Qu.: 2.0692 3rd Qu.: 541.0
Max. :164.00000 Max. :43.36 Max. : 4.2156 Max. :1572.0
if (!empty_nodes) summary(df.cluster03)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 86.0 Min. :-29.00 Min. : 0.00 Min. :0
1st Qu.: 6.00 1st Qu.:170.0 1st Qu.: 71.00 1st Qu.: 0.00 1st Qu.:0
Median :12.00 Median :195.0 Median :101.00 Median : 2.00 Median :0
Mean :11.68 Mean :200.2 Mean : 98.84 Mean : 15.12 Mean :0
3rd Qu.:17.00 3rd Qu.:228.0 3rd Qu.:127.00 3rd Qu.: 19.00 3rd Qu.:0
Max. :28.00 Max. :323.0 Max. :202.00 Max. :354.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-6.949 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:36.64 1st Qu.:-6.257 1st Qu.: 21.0
Median : 0.00000 Median :37.16 Median :-5.598 Median : 47.0
Mean : 0.01033 Mean :37.12 Mean :-4.833 Mean :110.6
3rd Qu.: 0.00000 3rd Qu.:37.78 3rd Qu.:-3.789 3rd Qu.: 90.0
Max. :10.00000 Max. :39.88 Max. :-0.500 Max. :717.0
if (!empty_nodes) summary(df.cluster04)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. : 14.0 Min. :-34.0 Min. : 0.000 Min. :0
1st Qu.:13.00 1st Qu.:211.0 1st Qu.:148.0 1st Qu.: 0.000 1st Qu.:0
Median :26.00 Median :234.0 Median :172.0 Median : 0.000 Median :0
Mean :26.31 Mean :229.6 Mean :165.2 Mean : 6.232 Mean :0
3rd Qu.:39.00 3rd Qu.:262.0 3rd Qu.:201.0 3rd Qu.: 2.000 3rd Qu.:0
Max. :53.00 Max. :384.0 Max. :263.0 Max. :490.000 Max. :0
prof_nieve longitud latitud altitud
Min. :0 Min. :27.82 Min. :-17.89 Min. : 14.0
1st Qu.:0 1st Qu.:28.05 1st Qu.:-16.56 1st Qu.: 25.0
Median :0 Median :28.44 Median :-16.33 Median : 33.0
Mean :0 Mean :28.35 Mean :-16.04 Mean : 369.8
3rd Qu.:0 3rd Qu.:28.48 3rd Qu.:-15.39 3rd Qu.: 64.0
Max. :0 Max. :28.95 Max. :-13.60 Max. :2371.0
if (!empty_nodes) summary(df.cluster05)
fecha_cnt tmax tmin precip nevada
Min. : 1.000 Min. :-22 Min. :-161.00 Min. : 0.0 Min. :0
1st Qu.: 3.000 1st Qu.: 90 1st Qu.: -11.00 1st Qu.: 0.0 1st Qu.:0
Median : 6.000 Median :112 Median : 9.00 Median : 6.0 Median :0
Mean : 6.479 Mean :110 Mean : 6.22 Mean : 16.3 Mean :0
3rd Qu.: 9.000 3rd Qu.:132 3rd Qu.: 26.00 3rd Qu.: 21.0 3rd Qu.:0
Max. :28.000 Max. :209 Max. : 82.00 Max. :608.0 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.0000 Min. :37.16 Min. :-8.411 Min. : 2
1st Qu.: 0.0000 1st Qu.:40.76 1st Qu.:-3.764 1st Qu.: 513
Median : 0.0000 Median :41.63 Median :-1.636 Median : 690
Mean : 0.3157 Mean :41.37 Mean :-1.370 Mean : 694
3rd Qu.: 0.0000 3rd Qu.:42.14 3rd Qu.: 1.331 3rd Qu.: 900
Max. :299.0000 Max. :43.36 Max. : 4.216 Max. :1572
if (!empty_nodes) summary(df.cluster06)
fecha_cnt tmax tmin precip nevada
Min. :29.00 Min. :-31.0 Min. :-155.0 Min. : 0.00 Min. :0
1st Qu.:44.00 1st Qu.:123.0 1st Qu.: 29.0 1st Qu.: 0.00 1st Qu.:0
Median :47.00 Median :157.0 Median : 62.0 Median : 6.00 Median :0
Mean :46.87 Mean :154.9 Mean : 58.3 Mean : 22.19 Mean :0
3rd Qu.:50.00 3rd Qu.:186.0 3rd Qu.: 89.0 3rd Qu.: 28.00 3rd Qu.:0
Max. :53.00 Max. :297.0 Max. : 187.0 Max. :690.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.00000 Min. :35.28 Min. :-8.624 Min. : 1.0
1st Qu.: 0.00000 1st Qu.:40.07 1st Qu.:-4.680 1st Qu.: 81.0
Median : 0.00000 Median :41.39 Median :-1.863 Median : 412.0
Mean : 0.09416 Mean :40.84 Mean :-1.924 Mean : 438.2
3rd Qu.: 0.00000 3rd Qu.:42.23 3rd Qu.: 1.165 3rd Qu.: 735.0
Max. :290.00000 Max. :43.57 Max. : 4.216 Max. :1572.0
if (!empty_nodes) summary(df.cluster07)
fecha_cnt tmax tmin precip nevada
Min. :14.00 Min. :172.0 Min. : 46.0 Min. : 0.00 Min. :0
1st Qu.:26.00 1st Qu.:246.0 1st Qu.:123.0 1st Qu.: 0.00 1st Qu.:0
Median :31.00 Median :277.0 Median :143.0 Median : 2.00 Median :0
Mean :30.62 Mean :278.6 Mean :143.2 Mean : 11.54 Mean :0
3rd Qu.:35.00 3rd Qu.:309.0 3rd Qu.:162.0 3rd Qu.: 13.00 3rd Qu.:0
Max. :51.00 Max. :428.0 Max. :266.0 Max. :422.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.00e+00 Min. :37.13 Min. :-8.624 Min. : 4.0
1st Qu.:0.00e+00 1st Qu.:40.48 1st Qu.:-5.498 1st Qu.: 405.0
Median :0.00e+00 Median :41.77 Median :-3.678 Median : 626.0
Mean :9.23e-03 Mean :41.52 Mean :-3.079 Mean : 598.2
3rd Qu.:0.00e+00 3rd Qu.:42.56 3rd Qu.:-1.411 3rd Qu.: 816.0
Max. :1.73e+02 Max. :43.57 Max. : 2.482 Max. :1894.0
if (!empty_nodes) summary(df.cluster08)
fecha_cnt tmax tmin precip nevada
Min. : 1.00 Min. :-79.0 Min. :-146.00 Min. : 0.00 Min. :0
1st Qu.:28.00 1st Qu.: 66.0 1st Qu.: 6.00 1st Qu.: 2.00 1st Qu.:0
Median :37.00 Median :120.0 Median : 48.00 Median : 16.00 Median :0
Mean :36.31 Mean :112.7 Mean : 40.82 Mean : 30.67 Mean :0
3rd Qu.:45.00 3rd Qu.:160.2 3rd Qu.: 81.00 3rd Qu.: 42.00 3rd Qu.:0
Max. :53.00 Max. :263.0 Max. : 154.00 Max. :459.00 Max. :0
prof_nieve longitud latitud altitud
Min. : 0.000 Min. :40.78 Min. :-4.0103 Min. :1405
1st Qu.: 0.000 1st Qu.:42.18 1st Qu.: 0.7317 1st Qu.:1894
Median : 0.000 Median :42.47 Median : 1.0544 Median :2230
Mean : 2.256 Mean :42.22 Mean : 0.7342 Mean :2133
3rd Qu.: 0.000 3rd Qu.:42.64 3rd Qu.: 1.7150 3rd Qu.:2400
Max. :805.000 Max. :42.77 Max. : 2.4378 Max. :2535
if (!empty_nodes) summary(df.cluster09)
fecha_cnt tmax tmin precip nevada
Min. :18.00 Min. :164.0 Min. : 73.0 Min. : 0.00 Min. :0
1st Qu.:28.00 1st Qu.:261.0 1st Qu.:157.0 1st Qu.: 0.00 1st Qu.:0
Median :34.00 Median :289.0 Median :181.0 Median : 0.00 Median :0
Mean :33.66 Mean :287.1 Mean :177.5 Mean : 10.43 Mean :0
3rd Qu.:39.00 3rd Qu.:314.0 3rd Qu.:202.0 3rd Qu.: 7.00 3rd Qu.:0
Max. :52.00 Max. :442.0 Max. :272.0 Max. :610.00 Max. :0
prof_nieve longitud latitud altitud
Min. :0.000000 Min. :35.28 Min. :-6.9492 Min. : 1.0
1st Qu.:0.000000 1st Qu.:38.00 1st Qu.:-1.1692 1st Qu.: 21.0
Median :0.000000 Median :40.82 Median : 0.6319 Median : 68.6
Mean :0.000884 Mean :39.88 Mean :-0.1911 Mean :115.1
3rd Qu.:0.000000 3rd Qu.:41.53 3rd Qu.: 1.9356 3rd Qu.:176.0
Max. :6.000000 Max. :43.36 Max. : 4.2156 Max. :691.0
if (!empty_nodes) summary(df.cluster10)
fecha_cnt tmax tmin precip
Min. : 1.00 Min. :-109.00 Min. :-189.00 Min. : 0.00
1st Qu.: 5.00 1st Qu.: 4.00 1st Qu.: -60.00 1st Qu.: 6.00
Median :10.00 Median : 34.00 Median : -31.00 Median : 25.00
Mean :10.56 Mean : 30.98 Mean : -35.71 Mean : 38.85
3rd Qu.:15.00 3rd Qu.: 62.00 3rd Qu.: -7.00 3rd Qu.: 55.00
Max. :25.00 Max. : 132.00 Max. : 56.00 Max. :615.00
nevada prof_nieve longitud latitud
Min. :0 Min. : 0.00 Min. :28.31 Min. :-16.4992
1st Qu.:0 1st Qu.: 0.00 1st Qu.:42.18 1st Qu.: 0.7789
Median :0 Median : 0.00 Median :42.47 Median : 1.0544
Mean :0 Mean : 19.98 Mean :42.25 Mean : 0.7410
3rd Qu.:0 3rd Qu.: 0.00 3rd Qu.:42.64 3rd Qu.: 1.7150
Max. :0 Max. :1073.00 Max. :42.77 Max. : 2.4378
altitud
Min. :1002
1st Qu.:1971
Median :2247
Mean :2186
3rd Qu.:2400
Max. :2535
if (!empty_nodes) {
df.clusters.dim <- c(dim(df.cluster01)[1], dim(df.cluster02)[1], dim(df.cluster03)[1], dim(df.cluster04)[1], dim(df.cluster05)[1], dim(df.cluster06)[1], dim(df.cluster07)[1], dim(df.cluster08)[1], dim(df.cluster09)[1], dim(df.cluster10)[1])
barplot(df.clusters.dim,
names.arg = c("cluster01", "cluster02", "cluster03", "cluster04", "cluster05", "cluster06", "cluster07", "cluster08", "cluster09", "cluster10"),
col = "steelblue1")
}
if (!empty_nodes) mpr.hist(df.cluster01)
if (!empty_nodes) mpr.hist(df.cluster02)
if (!empty_nodes) mpr.hist(df.cluster03)
if (!empty_nodes) mpr.hist(df.cluster04)
if (!empty_nodes) mpr.hist(df.cluster05)
if (!empty_nodes) mpr.hist(df.cluster06)
if (!empty_nodes) mpr.hist(df.cluster07)
if (!empty_nodes) mpr.hist(df.cluster08)
if (!empty_nodes) mpr.hist(df.cluster09)
if (!empty_nodes) mpr.hist(df.cluster10)
if (!empty_nodes) mpr.boxplot(df.cluster01)
if (!empty_nodes) mpr.boxplot(df.cluster02)
if (!empty_nodes) mpr.boxplot(df.cluster03)
if (!empty_nodes) mpr.boxplot(df.cluster04)
if (!empty_nodes) mpr.boxplot(df.cluster05)
if (!empty_nodes) mpr.boxplot(df.cluster06)
if (!empty_nodes) mpr.boxplot(df.cluster07)
if (!empty_nodes) mpr.boxplot(df.cluster08)
if (!empty_nodes) mpr.boxplot(df.cluster09)
if (!empty_nodes) mpr.boxplot(df.cluster10)
# Agrupa por longitud y latitud para rellenar el mapa con menos datos.
if (!empty_nodes) {
df.cluster01.grouped <- mpr.group_by_geo(df.cluster01)
df.cluster02.grouped <- mpr.group_by_geo(df.cluster02)
df.cluster03.grouped <- mpr.group_by_geo(df.cluster03)
df.cluster04.grouped <- mpr.group_by_geo(df.cluster04)
df.cluster05.grouped <- mpr.group_by_geo(df.cluster05)
df.cluster06.grouped <- mpr.group_by_geo(df.cluster06)
df.cluster07.grouped <- mpr.group_by_geo(df.cluster07)
df.cluster08.grouped <- mpr.group_by_geo(df.cluster08)
df.cluster09.grouped <- mpr.group_by_geo(df.cluster09)
df.cluster10.grouped <- mpr.group_by_geo(df.cluster10)
}
if (!empty_nodes) mpr.draw_map(spain, df.cluster01.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster02.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster03.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster04.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster05.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster06.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster07.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster08.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster09.grouped)
if (!empty_nodes) mpr.draw_map(spain, df.cluster10.grouped)